function controller
    warning('off', 'images:initSize:adjustingMag');

    %% Set up directory system to save data 

    %Valerie dirs
    %videoDir = 'C:\Users\vsimonis\Documents\MATLAB\NematodesMedia\Hoky1\';
    %workingDir = 'C:\Users\vsimonis\Documents\MATLAB\NematodesMedia\';

    %Ron dirs
   
    videoDir = 'C:\Users\rniehaus\Documents\Elegans\Videos\Test video loops of 300\';
    videoType = 'SeparateImages';
    workingDir = 'C:\Users\rniehaus\Documents\Elegans\';
    fileExt = '.tif';
    
    setEnv();
    studyInstanceName = sprintf('Study-RFUM294_%s', gettimestamp);


    %% Set up global variables

    %global wormMovie
    global dataList
    global suppData
    
    dataList = struct([]);
    suppData = struct([]);
  

    %Specify the algorithms to use for segmentation
    segFunct = @segWormVal;

    % Load the movie
    [wormVideo, nFrames, vidRows, vidCols] = loadVideo(videoType, videoDir, fileExt);
   
    %Process the frames
    tic
    startFrame = 1;
    endFrame =nFrames;
    frameRate = 2;
    processFrames(segFunct, wormVideo, startFrame, endFrame, frameRate);
    toc

    %% Save all data variables to disk 

    %Make a directory for the study instance
    status = mkdir(workingDir, studyInstanceName);

    %Save the path to the study instance dir for later use
    studyInstancePath = sprintf('%s%s\\', workingDir, studyInstanceName);
    studyInstanceProjFile = sprintf('%s%s.proj', workingDir, studyInstanceName);
    
    save(sprintf('%s%s', studyInstancePath, 'dataList'), 'dataList');
    save(sprintf('%s%s', studyInstancePath, 'suppData'), 'suppData', '-v7.3');
    f = fopen(studyInstanceProjFile, 'w');
    fprintf(f, 'Project File Data');
    fprintf(f, 'Study Instance Name: %s', studyInstanceName);
    fclose(f);


    %% IN addtion, save feature data to a csv file in the study instance folder 

    %Convert structure array to an array
    varName = transpose( fieldnames(dataList));
    wormDataArray = zeros(length(dataList), size(varName,2) );
    for i = 1:length(dataList)
         for j = 1: size(varName,2)
            
            wormDataArray(i,j) = dataList(i).(varName{j});
         end
    end

    %Create a dataset from the array and export it to csv file
    dataAndVariables =[{wormDataArray},varName];
    ds = dataset(dataAndVariables);
    export(ds,'File',sprintf('%s%s',studyInstancePath,'data.csv'),'delimiter',',') ;
end
